package com.home.base.core.framework.msg;

import com.home.base.core.framework.enums.ResultCodeEnum;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Description: 分页返回消息类,这里是 layui分页
 * Created by 王大宸 on 2020-09-23 0:32
 * Created with IntelliJ IDEA.
 */
public class PageResponse<T> implements Serializable {
    private static final long serialVersionUID = 4924770548665470983L;

    /**
     * layui 分页指定 code
     */
    private int code = 0;

    /**
     * 总条数
     */
    private long count;

    /**
     * 返回数据
     */
    private List<T> data;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 状态: 可以用于其他
     */
    private int status;

    public PageResponse(int status, Boolean success, long count, List<T> data) {
        if (count == 0) {
            this.msg = "暂无数据！";
        }
        this.count = count;
        this.data = data;
        this.status = status;
        this.success = success;
    }

    public PageResponse(int status, Boolean success, String msg, long count, List<T> data) {
        this.msg = msg;
        this.count = count;
        this.data = data;
        this.status = status;
        this.success = success;
    }

    /**
     * 请求成功
     */
    public static <T> PageResponse<T> ok(long count, List<T> data) {
        return new PageResponse<T>(ResultCodeEnum.PAGE_SUCCESS.getStatus(), ResultCodeEnum.PAGE_SUCCESS.getSuccess(), count, data);
    }

    /**
     * 请求错误
     */
    public static <T> PageResponse<T> err(long count, List<T> data) {
        return new PageResponse<T>(ResultCodeEnum.PAGE_ERROR.getStatus(), ResultCodeEnum.PAGE_SUCCESS.getSuccess(), count, data);
    }

    /**
     * 请求异常
     */
    public static <T> PageResponse<T> ex() {
        return new PageResponse<T>(ResultCodeEnum.PAGE_EXCEPTION.getStatus(), ResultCodeEnum.PAGE_EXCEPTION.getSuccess(), ResultCodeEnum.PAGE_EXCEPTION.getMessage(), 0, new ArrayList<T>());
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}
